﻿using BBCore.Server.Services;
using BootstrapBlazor.Components;
using Microsoft.AspNetCore.Components;
using System.Diagnostics.CodeAnalysis;

namespace BBCore.Server.Components.Pages.Admins
{
    public partial class RecordLock_Management
    {
        [NotNull]
        [Inject]
        RecordLockService? RecordLockService { get; set; }

        [NotNull]
        [Inject]
        ToastService? ToastService { get; set; }
        private async Task HandleCleanExpiredLocks()
        {

            var timeout = TimeSpan.FromMinutes(10); // 假设超时时间为 10 分钟
            RecordLockService.CleanExpiredLocks(timeout);
            await ToastService.Show(new ToastOption
            {
                Content = "成功清理过期锁",
                Category = ToastCategory.Success
            });
        }
        private void HandleRefresh()
        {
            // 若服务层需要手动刷新数据，可调用类似方法（如 RecordLockService.Refresh()）
            // 触发组件重新渲染
            StateHasChanged();
        }
        private async Task HandleReleaseLock(string lockKey)
        {
            RecordLockService.RemoveLock(lockKey);
            await ToastService.Show(new ToastOption
            {
                Content = $"成功释放锁: {lockKey}",
                Category = ToastCategory.Success
            });
        }

    }
}
